﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.IO;

namespace QLKHACHHANG
{
    public class SetConfig
    {
        // lay thong tin file cau hinh mau
        public static string getAppSettingModel(string key)
        {
            //Load the appsettings
            Configuration config = ConfigurationManager.OpenExeConfiguration(
                                    System.Reflection.Assembly.GetExecutingAssembly().Location);
            //Return the value which matches the key
            return config.AppSettings.Settings[key].Value;
        }
        // lay thong tin file cau hinh app.config
        public static string getAppSetting(string key)
        {
            //Load the appsettings
            Configuration config = ConfigurationManager.OpenExeConfiguration(
                                    System.IO.Path.Combine(Environment.CurrentDirectory, "app.config"));
            //Return the value which matches the key
            return config.AppSettings.Settings[key].Value;
        }
        // thiet lap thong tin file cau hinh mau
        public static void setAppSettingModel(string key, string value)
        {
            //Load appsettings
            Configuration config = ConfigurationManager.OpenExeConfiguration(
                                    System.Reflection.Assembly.GetExecutingAssembly().Location);
            //Check if key exists in the settings
            if (config.AppSettings.Settings[key] != null)
            {
                //If key exists, delete it
                config.AppSettings.Settings.Remove(key);
            }
            //Add new key-value pair
            config.AppSettings.Settings.Add(key, value);
            //Save the changed settings
            config.Save(ConfigurationSaveMode.Modified);
        }
        // thiet lap thong tin file cau hinh app.config
        public static void setAppSetting(string key, string value)
        {
            //Load appsettings         
            Configuration config = ConfigurationManager.OpenExeConfiguration(
                                    System.IO.Path.Combine(Environment.CurrentDirectory, "app.config"));
            //Check if key exists in the settings
            if (config.AppSettings.Settings[key] != null)
            {
                //If key exists, delete it
                config.AppSettings.Settings.Remove(key);
            }
            //Add new key-value pair
            config.AppSettings.Settings.Add(key, value);
            //Save the changed settings
            config.Save(ConfigurationSaveMode.Modified);
           
        }
    }
}
